package dept

import (
	"go-zero-project/common/global"
	"go-zero-project/common/response"
	"go-zero-project/common/validator"
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"go-zero-project/services/user/api/internal/logic/dept"
	"go-zero-project/services/user/api/internal/svc"
	"go-zero-project/services/user/api/internal/types"
)

func SubListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.DeptListReq
		if err := httpx.Parse(r, &req); err != nil {
			response.Response(w, nil, err)
			return
		}
		// 参数校验
		if err := validator.Validate(r.Context(), req, global.ZH); err != nil {
			response.Response(w, nil, err)
			return
		}
		l := dept.NewDeptSubListLogic(r.Context(), svcCtx)
		resp, err := l.DeptSubList(&req)
		response.Response(w, resp, err)
	}
}
